<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOperateLogs extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('operate_logs', function (Blueprint $table) {
            $table->id();
            $table->char('module', 32)->default('')->comment('业务');
            $table->char('business', 32)->default('')->comment('业务下的不同类型');
            $table->unsignedInteger('businessId')->default(0)->comment('业务表对应id');
            $table->unsignedInteger('userId')->default(0)->comment('rms userId');
            $table->string('userName', 32)->default('')->comment('用户姓名');
            $table->string('logName', 64)->default('')->comment('日志名称');
            $table->string('logContent', 255)->default('')->comment('日志内容');
            $table->unsignedInteger('logId')->default(0)->comment('日志关联的业务id');
            $table->tinyInteger('status')->default(0)->comment('0待处理 1已处理');

            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedAt')->default(0)->comment('修改时间');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('修改人');
            $table->unsignedInteger('isDeleted')->default(0);
            $table->collation = 'utf8mb4_general_ci';
            $table->comment = '通用操作日志';

            $table->index(['module', 'business', 'businessId'], 'idx_business_rel');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('operate_logs');
    }
}
